home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / BT_GET.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  3.3 KB  |  111 lines

  1. /*  bt_get.c - get_next, previous entries */
  2. #include   "stdio.h"
  3. #include   "btree.h"
  4. #include   "bt_macro.h"
  5.  
  6. extern    IX_DESC    *pci ;      /* global variable for current pix  */
  7. RECPOS    next_ix() ;
  8. RECPOS    last_ix() ;
  9.  
  10.  
  11. int  get_next(pe,pix)            /* get next entry */
  12.   ENTRY *pe ;                /* put entry here */
  13.   IX_DESC  *pix ;            /* points to an index descriptor */
  14.   {
  15.      BLOCK b ;
  16.  
  17.      pci = pix ;
  18.                 /* check for dummy entry at end-of-ix  */
  19.      copy_current(0,pe) ;
  20.      if( call(pci->pcomp)(pe,& pci->dx.dume) == 0 )
  21.     return( EOIX ) ;
  22.  
  23.      if( next_ix(0,&b) != NULLREC )    /* got next leaf entry ? */
  24.     {  copy_current(0,pe) ;     /* copy it */
  25.        return( IX_OK) ;        /* and return success */
  26.     }
  27.      else return( EOIX ) ;
  28.   }
  29.  
  30. RECPOS    next_ix(l,pb)            /* get next entry level */
  31.   int    l ;                /* level number */
  32.   BLOCK *pb ;
  33.   {
  34.      int   off     ;
  35.      RECPOS   newblk ;
  36.  
  37.      if( l >= pci->dx.nl )        /* above top level ? */
  38.     return( NULLREC ) ;        /* yes - failure */
  39.  
  40.      retrieve_block(l,CB(l),pb,CURR) ;    /* get current block */
  41.      off = next_entry(pb,CO(l)) ;    /* move to next entry in block */
  42.      if( off >= 0 )            /* past end of block */
  43.     CO(l) = off ;            /* no - record new position */
  44.                     /* yes - move to next index block */
  45.      else
  46.     {
  47.        newblk = next_ix(l+1,pb) ;    /* next block on this level */
  48.        if( newblk != NULLREC )    /* check for beginning of index */
  49.           {  CB(l) = newblk ;    /* make this current block */
  50.          retrieve_block(l,CB(l),pb,CURR) ; /* put in memory */
  51.          CO(l) = 0 ;        /* at first entry */
  52.           }
  53.        else return( NULLREC ) ;    /* at begin. of index - can't */
  54.     }
  55.      return( ENT_ADR(pb,CO(l))->rptr ) ; /* block no. lower level */
  56.   }
  57.  
  58.  
  59. int  get_previous(pe,pix)        /* get previous index entry */
  60.   ENTRY *pe ;                /* put the entry here */
  61.   IX_DESC  *pix ;            /* points to an index descriptor */
  62.   {
  63.      BLOCK b ;
  64.  
  65.      pci = pix ;
  66.      if( last_ix(0,&b) != NULLREC )    /* got next leaf entry ? */
  67.     {  copy_current(0,pe) ;     /* yes - return it */
  68.        return( IX_OK ) ;        /* and success code */
  69.     }
  70.      else return( EOIX ) ;        /* no - at BOF. return failure */
  71.   }
  72.  
  73. RECPOS    last_ix(l,pb)            /* get previous entry from a level */
  74.   int    l ;                /* level number */
  75.   BLOCK *pb ;                /* space for block */
  76.   {
  77.      int   off ;
  78.      RECPOS   newblk ;
  79.  
  80.      if( l >= pci->dx.nl )
  81.     return( NULLREC ) ;
  82.  
  83.      retrieve_block(l,CB(l),pb,CURR) ;    /* get current block */
  84.      off = prev_entry(pb,CO(l)) ;    /* back up one entry */
  85.      if( off >= 0 )            /* past beginning of block */
  86.     CO(l) = off ;            /* no - record new offset */
  87.      else
  88.     {  newblk = last_ix(l+1,pb);    /* yes - get previous block */
  89.        if(     newblk != NULLREC )    /* check for begin of index */
  90.           {  CB(l) = newblk ;    /* make this the current block */
  91.          retrieve_block(l,CB(l),pb,CURR) ; /* put into memory */
  92.          CO(l) = last_entry(pb) ; /* offset = last entry */
  93.           }
  94.        else return( NULLREC ) ;    /* at beginning of index - */
  95.     }                /* can't back up */
  96.                     /* record ptr in curr. entry */
  97.      return( ENT_ADR(pb,CO(l))->rptr ) ;
  98.   }
  99.  
  100.  
  101. int  get_current(pe,pix)        /* get current index entry */
  102.   ENTRY *pe ;                /* put the entry here */
  103.   IX_DESC  *pix ;            /* points to an index descriptor */
  104.   {
  105.      pci = pix ;
  106.      copy_current(0,pe) ;        /* copy it */
  107.   }
  108.  
  109.  
  110.  
  111.